home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / STRIPPHI.C < prev    next >
Text File  |  1985-05-29  |  1KB  |  63 lines

  1. /*
  2.  * Program to read a file, strip the high bits from each character,
  3.  * then discard non-printable characters.
  4.  */
  5. #include "stdio.h"
  6. #define ASCIICHR 0x7f
  7. main(argc,argv)
  8.     int argc;
  9.     char *argv[];
  10.     {
  11.     int  c,
  12.      outfile,
  13.      infile;
  14.     if (argc == 1)
  15.     {
  16.     puts("\n");
  17.     puts("Syntax: STRIPPHI <infile> <outfile>\n");
  18.     puts("where   infile  is the filespec for the input data\n");
  19.     puts("        outfile is the filespec for the output data\n\n");
  20.     exit(0);
  21.     }
  22.     if (argc == 1)
  23.     {
  24.     puts("Author:  Peter Townsend\n");
  25.     puts("Date:    28May85\n");
  26.     puts("Version: 1.0\n");
  27.     }
  28.     if ((infile = open(argv[1],0)) == -1)
  29.     {
  30.     printf("\nCannot open input file %s\n",argv[1]);
  31.     exit(1);
  32.     }
  33.     if (argc == 2)
  34.     {
  35.     printf("\nMissing Output Filename\n");
  36.     exit(1);
  37.     }
  38.     if (strcmp(argv[1],argv[2]) == 0)
  39.     {
  40.     printf("\nInput filename and output filename cannot be the same.\n");
  41.     exit(1);
  42.     }
  43.     if ((outfile = open(argv[2],1)) == -1)
  44.     {
  45.     if ((outfile = creat(argv[2])) == -1)
  46.         {
  47.         printf("\nCannot open/create output file %s\n",argv[2]);
  48.         exit(1);
  49.         }
  50.     }
  51.     while ((c = fgetc(infile)) != EOF)
  52.     {
  53.     c = (c & ASCIICHR);
  54.     if (isprint(c))
  55.         {
  56.         putc(c,outfile);
  57.         }
  58.     }
  59.     fclose(infile);
  60.     fclose(outfile);
  61.     exit(0);
  62.     }
  63.